package com.example.MyRESTAssured.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class XMLController {


    /**
     * 第一次使用post请求,有参数传入，返回值是xml
     * @return
     */
    @RequestMapping(value = "/greetXML",method = RequestMethod.POST )
    @ResponseBody
    public String makePostRequest(String firstName,String lastName){

        String res="<greeting>\n" +
                "   <firstName>"+firstName+"</firstName>\n" +
                "   <lastName>"+lastName+"</lastName>\n" +
                "</greeting>";
        return res;
    }

    /**
     * 测试xml文件中的命名空间和URL
     * @return
     */
    @RequestMapping(value = "/namespace",method = RequestMethod.GET )
    @ResponseBody
    public String validateNameSpaceGetRequest(){

        String res="<foo xmlns:ns=\"http://localhost/\">\n" +
                "  <bar>sudo </bar>\n" +
                "  <ns:bar>make me a sandwich!</ns:bar>\n" +
                "</foo>";
        return res;
    }

    @RequestMapping(value = "/groovy",method = RequestMethod.GET )
    @ResponseBody
    public String validateGroovyGetRequest(){

        String res="<shopping>\n" +
                "      <category type=\"groceries\">\n" +
                "        <item>Chocolate</item>\n" +
                "        <item>Coffee</item>\n" +
                "      </category>\n" +
                "      <category type=\"supplies\">\n" +
                "        <item>Paper</item>\n" +
                "        <item quantity=\"4\">Pens</item>\n" +
                "      </category>\n" +
                "      <category type=\"present\">\n" +
                "        <item when=\"Aug 10\">Kathryn's Birthday</item>\n" +
                "      </category>\n" +
                "</shopping>";
        return res;
    }


}
